<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="Clases.*" %>
<%@ page import="Datos.TurnoAdapter" %>
<%@ page import="Datos.ProfesionalAdapter" %>
<%@ page import="java.util.ArrayList" %>
<%
TurnoAdapter adapter = new TurnoAdapter();
ArrayList<Turno> turnos = new ArrayList<Turno>();
ProfesionalAdapter a = new ProfesionalAdapter();
ArrayList<Profesional> array = new ArrayList<Profesional>();
int idprof=0, idsec=0;
%>
<%if (session.getAttribute("UsuarioActual")!=null){ %>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Turnos</title>
<link rel="shortcut icon" href="images/favicon.ico" />
<link href="dist/css/bootstrap.min.css" rel="stylesheet" />
<link href="css/listarstyle.css" rel="stylesheet" />
<!-- Calendario -->
<link href="css/flick/jquery-ui-1.9.1.custom.css" rel="stylesheet">
<script src="js/jquery-1.8.2.js"></script>
<script src="js/jquery-ui-1.9.1.custom.min.js"></script> 
<script>
$(function() {
$("#fecha").datepicker({ dateFormat: "yy-mm-dd" });
});
</script>
</head>

<body>
<%if(Integer.parseInt(session.getAttribute("Tipo").toString())==1){ %>
<%  idsec = Integer.parseInt(session.getAttribute("IdSecretaria").toString()); %>
<% 	array = a.getAllProfesionales(idsec); %>
<%@include file="menusecretarias.jsp" %>
<%}else{
	idprof = Integer.parseInt(session.getAttribute("IdProfesional").toString());
%>
<%@include file="menuprofesionales.jsp" %>
<%} %>
<div class="container">
	<div class="starter-template">
		<div class="main">
			<div class="header_bg">
				<div class="header">
				</div>
				<div class="clr"></div>
			</div>
			<div class="clr"></div>
			<div class="clr"></div>
		  <div class="body_resize">
		    <div class="body">
		      <div class="body_listar">
		        <h2>LISTADO DE TURNOS</h2>
		        <table align="center" width="900" border="0" cellspacing="1" cellpadding="3">
		          <tr>
		            <td height="40" colspan="2"><%if(idprof==0){%>
		            <% if(array.size()>0){%>
		            <a href="registrarturno.jsp?TipoAccion=0&idProf=<%=(request.getParameter("profesional")!=null)?request.getParameter("profesional"):0%>">
		            <img src="images/add.png" width="16" height="16" align="left" style="margin: 4px 10px 0 0;" />Agregar un Turno</a>
		            <%}else{%><span id="error_message_title">DEBE CARGAR PROFESIONALES</span><%}%><%}%></td>
		            <td height="40" colspan="5"><div  align="right">
		            <form id="form1" name="form1" method="get" action="">
		         
		              <%if(idprof!=0){ %><label for="fecha">Fecha</label>
		              <input name="fecha" type="text" id="fecha" value="" readonly="readonly"  class="text"/>
		              <%} %>
		              <%if(idprof==0){ %>
		              <label for="profesional">Profesional</label> 	
		              <select name="profesional"  id ="profesional">
				     	<option value="0">Todos</option>
				     	<% 			     	
				     	String sel ="";
				 		for(Profesional pro: array) 
				     	{if(request.getParameter("profesional") != null && Integer.parseInt(request.getParameter("profesional"))==pro.getId()){sel="selected='selected'";}
				     		else sel = "";
				     	%><option value="<%out.print(pro.getId());%>" <%out.print(sel);%>><%out.print(pro.getApellido()+", "+pro.getNombre());%></option>
				     	<%} } %>
				    </select> 
		              <!-- <input type="text" name="txt" id="txt" value="" /> -->
		              <input type="submit" name="buscar" id="buscar" value="SELECCIONAR" />
		              
		            </form></div></td>
		          </tr>
		          <tr>
		            <td width="100" bgcolor="#CCCCCC">Profesional</td>
		            <td width="150" bgcolor="#CCCCCC">Horario</td>
		            <td width="70" bgcolor="#CCCCCC">Cliente</td>
		            <td width="200" bgcolor="#CCCCCC">Motivo</td>
		            <td width="100" bgcolor="#CCCCCC">Observaciones</td>
		            <%if(idprof==0) {%><td width="60" bgcolor="#CCCCCC"><strong>Editar</strong></td>
		            <td width="60" bgcolor="#CCCCCC"><strong>Eliminar</strong></td><%} %>
		          </tr>
		          <%if(request.getParameter("profesional") != null && Integer.parseInt(request.getParameter("profesional"))!=0)
		          {
		        	  turnos = adapter.getAllTurnos(Integer.parseInt(request.getParameter("profesional")));
		          }
		          else {
		        	  if(idprof !=0){
		        		  if(request.getParameter("fecha")!=null)turnos = adapter.getAllTurnosPorFecha(request.getParameter("fecha"),idprof);
		        		  else turnos = adapter.getAllTurnos(idprof);		        		  
		        	  }else {
		        	  turnos = adapter.getAllTurnosPorSecretaria(idsec);
		        	  } 
		        	  
		          }%>
		          	<%for(Turno tur:turnos) {%>
					            <tr>
					              <td width="100" ><%=tur.getNomProfesional()%></td>
					              <td width="150" ><%out.print(tur.getFecha()+" "+tur.getHorario());%></td>
					              <td width="70" ><%=tur.getCliente()%></td>
					              <td width="200" ><%=tur.getMotivo() %></td>
					              <td width="100" ><%=tur.getObservaciones()%></td>
					              <%if(idprof==0) {%><td width="60" ><a href="registrarturno.jsp?id=<%=tur.getId()%>">Editar</a></td>
					              <td width="60" >
					              <a href="Final_IUDTurno?idTurno=<%=tur.getId()%>" onclick="return confirmar('¿Seguro que deseas eliminar el registro?')">Eliminar
					              </a></td><%} %>
					            </tr>
					 <%}%>
		          <tr>
		            <td colspan="7" align="right">
		            Cantidad de registros: <%=turnos.size() %> 
		            </td>
		          </tr>
		        </table>
		        <p>&nbsp;</p>
		      </div>
		      <div class="clr"></div>
		    </div>
		    <div class="clr"></div>
		  </div>
		</div>
</div>
</div>
<!-- Alerta confirmar eliminación -->
    <script language="JavaScript"> 
	function confirmar ( mensaje ) { return confirm( mensaje ); } 
	</script>
<!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="dist/js/bootstrap.min.js"></script>
</body>
</html><%} else response.sendRedirect("LoginProfesional.jsp"); %>
